package com.taichuan.selfcheck.utils;

import android.content.Context;
import android.view.ViewGroup;

import com.taichuan.selfcheck.ad.ADArea;
import com.taichuan.selfcheck.ad.ADView;
import com.taichuan.selfcheck.ad.EADArea;

/**
 * Created by hyC on 2020/1/8 14:09
 */
public class ADViewPersistent {

    private ADView mTestADView;
    private ADView mFullADView;
    private ADView mCallADView;

    public static ADViewPersistent get() {
        return ADViewPersistentHolder.holder;
    }

    public ADView getTestADView(Context context) {
        if (mTestADView == null) {
            mTestADView = new ADView(context);
            mTestADView.init(new ADArea(EADArea.X1));
        }
        if (mTestADView.getParent() != null) {
            ((ViewGroup) mTestADView.getParent()).removeView(mTestADView);
        }
        return mTestADView;
    }

    public ADView getFullADView(Context context) {
        if (mFullADView == null) {
            mFullADView = new ADView(context);
            mFullADView.init(new ADArea(EADArea.X2, true));
        }
        if (mFullADView.getParent() != null) {
            ((ViewGroup) mFullADView.getParent()).removeView(mTestADView);
        }
        return mFullADView;
    }

    public ADView getCallADView(Context context) {
        if (mCallADView == null) {
            mCallADView = new ADView(context);
            mCallADView.init(new ADArea(EADArea.X1, false, ADArea.PlayedType.IMAGE));
        }
        if (mCallADView.getParent() != null) {
            ((ViewGroup) mCallADView.getParent()).removeView(mCallADView);
        }
        return mCallADView;
    }

    private static final class ADViewPersistentHolder {
        private static ADViewPersistent holder = new ADViewPersistent();
    }

}
